<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function arr(s, spaces) {
      let left = 0;
      let res = '';
      spaces.forEach((item) => {
        res += `${s.substring(left, item)} `;
        left = item;
      })
      res += s.substring(left, s.length);
      return res;
    };
    console.log(arr(s = "EnjoyYourCoffee", spaces = [5, 9]));
  </script>
</body>

</html>